# -*- coding: utf-8 -*
import os
import platform
from abc import ABCMeta, abstractmethod

from typing import List


class Collector(metaclass=ABCMeta):
    """数据收集器基类"""
    metrics = []

    def __init__(self, is_test: bool):
        self.is_test = is_test
        self.stash = []

    @classmethod
    def get_metrics(cls) -> List[float]:
        """获取收集器收集到的指标列表"""
        return cls.metrics

    @staticmethod
    def get_test_file_path(file_name: str, file_pointer: str) -> str:
        """获取测试文件的具体路径"""
        if platform.system() == "Windows":
            file_path = os.path.abspath(file_pointer)  # dirname在linux下可用，windows写代码暂时使用abspath
            file_path_prefix = "\\".join(file_path.split("\\")[:-1])
            test_file_path = os.path.join(file_path_prefix, "baseline.csv", file_name)
        elif platform.system() == "Linux":
            dir_path = os.path.dirname(file_pointer)
            test_file_path = os.path.join(dir_path, "baseline.csv", file_name)
        return test_file_path

    @abstractmethod
    def collect(self) -> None:
        pass

    def gather(self) -> None:
        for item in self.stash:
            self.metrics.append(item)

    def clear(self) -> None:
        self.metrics.clear()